package com.yeqifu.bus.controller;

import com.yeqifu.bus.domain.Customer;
import com.yeqifu.bus.service.ICustomerService;
import com.yeqifu.bus.vo.CustomerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户管理控制器
 */
@RestController  //以json形式响应数据
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    private ICustomerService customerService;

    /**
     * 加载客户列表返回DataGridView
     * @param customer
     * @return
     */
    @RequestMapping("loadAllCustomer")
    public List<Customer> loadAllCustomer(Customer customer){
        List<Customer> customerList = customerService.getCustomerList(customer);
        return customerList;
    }

    /**
     * 添加一个客户
     * @param customer
     * @return
     */
    @RequestMapping("addCustomer")
    public int addCustomer(Customer customer){
        int i = customerService.addCustomer(customer);
        return i;
    }

    /**
     * 修改一个客户
     * @param customer
     * @return
     */
    @RequestMapping("updateCustomer")
    public int updateCustomer(Customer customer){
        int i=customerService.updateCustomer(customer);
        return i;
    }

    /**
     * 删除一个客户
     * @param customer
     * @return
     */
    @RequestMapping("deleteCustomer")
    public String deleteCustomer(Customer customer){
        String i=customerService.deleteCustomer(customer);
        return i;
    }

    /**
     * 批量删除客户
     * @param customerVo
     * @return
     */
    @RequestMapping("deleteBatchCustomer")
    public void deleteBatchCustomer(CustomerVo customerVo){
         customerService.deleteBatchCustomer(customerVo.getIds());
    }

}
